var mongoose = require('mongoose')
//连接数据库
mongoose.connect('mongodb://localhost/spitdb')
var Schema = mongoose.Schema
//创建文档结构
var userSchema = new Schema({
    username:  String,
    password: String,
    sex:   String
  });
  //将文档结构发布为模型  第一个参数为集合名称,User会转成users
  var User = mongoose.model('User',userSchema)
  //保存
 var admin = new User({
     username:'admin',
     password:'123',
     sex:'男'
 })
 admin.save(function (err,result) {
     if(err){
         console.log('保存失败');
     } else{
        console.log('保存成功');
        //打印插入成功后的数据
        console.log(result);
     }
 })



